package com.fulihui.information.biz.conv;

import com.fulihui.information.dal.dataobj.InfoSource;
import com.fulihui.information.dto.SourceDTO;

import java.util.List;
import java.util.stream.Collectors;

import static java.util.Collections.emptyList;
import static org.springframework.util.CollectionUtils.isEmpty;

/**
 * 渠道信息转换器
 * @author LeeSon on 2016/12/28 0028.
 */
public class SourceConv {
    public static SourceDTO toDTO(InfoSource source) {
        if (source == null) {
            return null;
        }
        SourceDTO dto = new SourceDTO();
        dto.setCode(source.getCode());
        dto.setName(source.getName());
        dto.setCheck(source.getCheck());
        dto.gmtCreate(source.getGmtCreate());
        dto.gmtModified(source.getGmtModified());
        return dto;
    }

    public static List<SourceDTO> toList(List<InfoSource> list) {
        if (isEmpty(list)) {
            return emptyList();
        }
        return list.stream().map(SourceConv::toDTO).collect(Collectors.toList());
    }
}